--测试环境
--package.path = package.path..";?.lua"
--生产环境
package.path = "./plugin/IOTIN/utils.lua"..";..\\?.lua"

require ("utils")

rxBuf = {}

function NewVariables()
    -- body
    local VariableMap = {
        Variable = {
        },
    }
    return VariableMap
end

function GenerateGetRealVariables(sAddr,step)
    
    -- body
    local requestADU = {}
    local VariableMap = {
        Status = "1",
        Variable = {},
    }

    if(step == 0)
    then
        VariableMap = {
            Status = "0",
            Variable = requestADU
        }
    end

    return VariableMap
end

function DeviceCustomCmd(sAddr,cmdName,cmdParam,step)
    
    -- body
    local requestADU = {}
    local VariableMap = {
        Status = "1",
        Variable = {},
    }

    if(step == 0)
    then
        if(cmdName == "GetRealVariables")
        then
            VariableMap = {
                Status = "0",
                Variable = requestADU
            }
        end
    end

    return VariableMap
end

function AnalysisRx(sAddr,rxBufCnt)
    -- body
    local VariableMap = {
        Status = "1",
        Variable = {},
    }
    --print("rxBufCnt:" .. string.format("%d",rxBufCnt))
    if(rxBufCnt < 1)
    then
        rxBuf = {}
        return VariableMap
    end

    for index=1,rxBufCnt,1 do
        local Variable = {}
        local VariableIndex = 1
        --print("rxBuf:" .. string.format("%X",rxBuf[1]))
        if(rxBuf[1] == 0x31)
        then
            Variable[VariableIndex]  = utils.AppendVariable(VariableIndex,"IoInputStatus",1,1)
            VariableIndex = VariableIndex + 1
        elseif(rxBuf[1] == 0x30)
        then
            Variable[VariableIndex]  = utils.AppendVariable(VariableIndex,"IoInputStatus",0,0)
            VariableIndex = VariableIndex + 1
        end

        VariableMap = {
            Status = "0",
            Variable = Variable
        }
        rxBuf = {}
        return VariableMap
    end

    rxBuf = {}
    return VariableMap
end    


--GenerateGetRealVariables("/sys/class/gpio/gpio203/value",0)
